package main

import "fmt"

var globalVar = "我是全局变量" // 整个包范围内有效

func test1() {
	localVar := "我是局部变量" // 仅在声明函数内有效
	fmt.Println(globalVar)
	fmt.Println(localVar)
}

func test2() {
	var a int = 42
	var b int8 = 127
	var c int = -32000
	fmt.Println(a, b, c)

	var d uint = 42
	var e uint8 = 255
	var f uint16 = 60000
	fmt.Println(d, e, f)

	var g float32 = 3.14
	var h float64 = 2.1145141919810
	fmt.Println(g, h)

	var i bool = true
	var j bool = false
	fmt.Println(i, j)

	var k string = "Hello, Golang"
	fmt.Println(k)

	var arr [3]int = [3]int{1, 2, 3}
	fmt.Println(arr)

	slice := []int{1, 2, 3, 4, 5}
	slice = append(slice, 6)
	fmt.Println(slice)

	m := map[string]int{"a": 1, "b": 2}
	fmt.Println(m)

	type Person struct {
		Name string
		Age  int
	}
	p := Person{Name: "李田所", Age: 24}
	fmt.Println(p)
}

func test3() {
	// 分支语句
	var age = 21
	if age > 18 {
		fmt.Println("成年")
	} else {
		fmt.Println("未成年")
	}

	// for 循环
	for i := 0; i < 5; i++ {
		fmt.Println(i)
	}
	// 无限循环
	//for {
	//	fmt.Println("无限循环")
	//}

	// range 循环
	arr := []int{10, 20, 30}
	for index, value := range arr {
		fmt.Println(index, value)
	}
}

//func main() {
//	// test1()
//	// test2()
//	// test3()
//}
